﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ObserverAndMediator
{
    /// <summary>
    /// 被觀察者
    /// </summary>
    public abstract class Observable
    {

        //定義一個觀察者數組
        private List<Observer> _observers = new List<Observer>();

        /// <summary>
        /// 增加一個觀察者
        /// </summary>
        /// <param name="observer"></param>
        public void addObserver(Observer observer)
        {
            _observers.Add(observer);
        }

        /// <summary>
        /// 刪除一個觀察者
        /// </summary>
        /// <param name="observer"></param>
        public void deleteObserver(Observer observer)
        {
            _observers.Remove(observer);
        }



        //public abstract void notifyEventDispatch();

        /// <summary>
        /// 通知所有觀察者
        /// </summary>
        public void notifyObservable(object obj)
        {
            foreach (var o in _observers)
            {
                o.update(this,obj);
            }
        }

    }
}
